package com.yc.str;

/**
 * 匿名内部类的实现
 */
public class MeaningOfThis {
    public final int value = 4;

    public void doIt() {
        int value = 6;
        Runnable r = new Runnable() {

            public final int value = 5;
            @Override
            public void run() {
                int value = 10;
                System.out.println(this.value);
            }
        };
        r.run();
    }

    public static void process(Runnable r) {
        r.run();
    }

    public static void main(String[] args) {
        MeaningOfThis m = new MeaningOfThis();
        m.doIt();  // 输出值为5， 因为this指的是包含它的Runnable, 而不是外面的类


        process(() -> System.out.println("hello"));
        process(() -> { System.out.println("hello"); } );
    }
}
